package blackstar.performance.logger;

import java.util.Calendar;

/**
 * @author RayWoo (ayufox@gmail.com)
 *
 */
public final class MessageBuilder
{
	public final static String LINE_SEP = System.getProperty("line.separator");

	public final static char SPLIT = '|';

	private StringBuilder message;

	public MessageBuilder(int capacity)
	{
		this.message = new StringBuilder(capacity);
	}

	public MessageBuilder()
	{
		this.message = new StringBuilder(128);
	}

	public StringBuilder getMessage()
	{
		return message;
	}

	public void appendSplit()
	{
		message.append(SPLIT);
	}

	public void append(String msg)
	{
		message.append(msg);
	}

	public void append(long msg)
	{
		message.append(msg);
	}

	public void appendLineSep()
	{
		message.append(LINE_SEP);
	}

	public void appendTimestamp()
	{
		Calendar calendar = Calendar.getInstance();
		message.append(calendar.get(Calendar.YEAR));
		if (calendar.get(Calendar.MONTH) < 9)
		{
			message.append('0');
		}
		message.append(calendar.get(Calendar.MONTH) + 1);
		if (calendar.get(Calendar.DAY_OF_MONTH) < 10)
		{
			message.append('0');
		}
		message.append(calendar.get(Calendar.DAY_OF_MONTH));
		if (calendar.get(Calendar.HOUR_OF_DAY) < 10)
		{
			message.append('0');
		}
		message.append(calendar.get(Calendar.HOUR_OF_DAY));
		if (calendar.get(Calendar.MINUTE) < 10)
		{
			message.append('0');
		}
		message.append(calendar.get(Calendar.SECOND));
		if (calendar.get(Calendar.MINUTE) < 10)
		{
			message.append('0');
		}
		message.append(calendar.get(Calendar.SECOND));
	}
}